package fivestar.ui.country;

import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.jdesktop.swingx.JXDatePicker;
import org.kazao.calendar.KazaoCalendarDate;
import org.netbeans.validation.api.ValidatorUtils;
import org.netbeans.validation.api.builtin.stringvalidation.StringValidators;
import org.netbeans.validation.api.ui.ValidationGroup;
import org.netbeans.validation.api.ui.swing.ValidationPanel;
import org.pushingpixels.substance.api.skin.SubstanceBusinessBlackSteelLookAndFeel;

public class Register extends javax.swing.JDialog implements ActionListener,
		ItemListener, KeyListener {

	private static final long serialVersionUID = -4800414210063077974L;

	private JLabel lblCountryName;
	JLabel lblGuest;
	JLabel lblNewLabel;
	private JTextField txtCountryName;
	private JButton btnAdd, btnCancel;
	private JPanel pnlCountry, pnlTitle, pnlInformation, pnlOption;
	JSeparator separator;
	String ruta = "No tiene";
	String country = "";

	private KazaoCalendarDate txtBirthDate;
	private JXDatePicker datePicker;
	private ButtonGroup groupGender;
	ValidationPanel pnlValidation;
	ValidationGroup group;

	public Register(Frame parent, boolean modal) {
		super(parent, modal);
		setTitle("New Country");
		setResizable(false);
		initComponents();
		this.setLocationRelativeTo(null);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void initComponents() {
		try {

			getContentPane().setLayout(null);

			pnlCountry = new JPanel();
			pnlCountry.setBounds(5, 5, 359, 209);
			pnlCountry.setLayout(null);
			getContentPane().add(pnlCountry);

			pnlValidation = new ValidationPanel();
			pnlValidation.setBounds(0, 0, 369, 244);
			pnlValidation.setInnerComponent(pnlCountry);
			getContentPane().add(pnlValidation);
			group = pnlValidation.getValidationGroup();

			pnlTitle = new JPanel();
			pnlTitle.setForeground(new Color(0, 0, 0));
			pnlTitle.setBounds(10, 0, 341, 67);
			pnlCountry.add(pnlTitle);
			pnlTitle.setLayout(null);

			separator = new JSeparator();
			separator.setBounds(5, 36, 321, 2);
			pnlTitle.add(separator);

			lblGuest = new JLabel("Country");
			lblGuest.setHorizontalAlignment(SwingConstants.LEFT);
			lblGuest.setVerticalAlignment(SwingConstants.TOP);
			lblGuest.setFont(new Font("Tahoma", Font.PLAIN, 30));
			lblGuest.setBounds(10, 0, 233, 38);
			pnlTitle.add(lblGuest);

			lblNewLabel = new JLabel("Register");
			lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
			lblNewLabel.setVerticalAlignment(SwingConstants.BOTTOM);
			lblNewLabel.setForeground(new Color(0, 0, 0));
			lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 20));
			lblNewLabel.setBounds(10, 36, 233, 27);
			pnlTitle.add(lblNewLabel);

			groupGender = new ButtonGroup();

			// Tabla Location
			pnlInformation = new JPanel();
			pnlInformation.setBounds(10, 78, 341, 67);
			pnlCountry.add(pnlInformation);
//			pnlInformation.setBorder(BorderFactory.createTitledBorder(null, "",
//					TitledBorder.DEFAULT_JUSTIFICATION,
//					TitledBorder.DEFAULT_POSITION, new Font("Tahoma", 0, 10)));
			pnlInformation.setLayout(null);

			lblCountryName = new JLabel("Country Name :");
			lblCountryName.setHorizontalAlignment(SwingConstants.TRAILING);
			lblCountryName.setBounds(10, 23, 112, 26);
			lblCountryName.setFont(new Font("Tahoma", Font.PLAIN, 11));
			pnlInformation.add(lblCountryName);

			txtCountryName = new JTextField();
			txtCountryName.setBounds(150, 23, 147, 27);
			txtCountryName.setName("Country Name");
			txtCountryName.addKeyListener(this);
			txtCountryName.setFont(new Font("Tahoma", Font.PLAIN, 11));
			pnlInformation.add(txtCountryName);

			pnlOption = new JPanel();
			pnlOption.setBounds(0, 165, 359, 30);
			pnlCountry.add(pnlOption);
			pnlOption.setLayout(null);

			btnAdd = new JButton("Add");
			btnAdd.setEnabled(false);
			btnAdd.setBounds(128, 0, 98, 28);
			pnlOption.add(btnAdd);
			btnAdd.setFont(new Font("Tahoma", Font.PLAIN, 10));

			btnCancel = new JButton("Cancel");
			btnCancel.setBounds(236, 0, 98, 28);
			pnlOption.add(btnCancel);
			btnCancel.setFont(new Font("Tahoma", Font.PLAIN, 10));
			btnCancel.addActionListener(this);
			btnAdd.addActionListener(this);

			group.add(txtCountryName, ValidatorUtils
					.merge(StringValidators.REQUIRE_NON_EMPTY_STRING));

			setSize(375, 283);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void keyPressed(KeyEvent evt) {
		// TODO Auto-generated method stub
		// if(evt.getSource()== txtDNI){
		// if(!(txtDNI.getText().equals("")))
		// btnAdd.setEnabled(true);
		// else{
		// btnAdd.setEnabled(false);
		// }
		// }
	}

	@Override
	public void keyReleased(KeyEvent evt) {

	}

	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void itemStateChanged(ItemEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub

	}

	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					// JRibbonFrame.setDefaultLookAndFeelDecorated(true);
					JDialog.setDefaultLookAndFeelDecorated(true);
					UIManager.setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
				} catch (UnsupportedLookAndFeelException unsupportedLookAndFeelException) {
					System.out.println(unsupportedLookAndFeelException
							.getMessage());
				}
				Register dialog = new Register(null, true);
				dialog.addWindowListener(new java.awt.event.WindowAdapter() {
					public void windowClosing(java.awt.event.WindowEvent e) {
						System.exit(0);
					}
				});
				dialog.setVisible(true);

			}
		});
	}
}
